/*
* berton
*/
package com.pitop.t.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.t.entity.Permission;
import com.pitop.t.service.TpermissionSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
*  控制器
*
* @author berton
*/
@RestController
@RequestMapping("/tpermission")
@Slf4j
@Api(value = "控制器", description = "控制器")
public class TpermissionCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private TpermissionSV tpermissionSV;

    /**
    * 查询Tpermission一个详情信息
    * @param permissionId 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Tpermission一个详情信息", notes = "查询Tpermission一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "permissionId", value = "",dataType = "java.lang.Integer", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public Permission load(java.lang.Integer permissionId) {
        if(permissionId==null){
        return null;
        }
        Permission tpermission = tpermissionSV.load(permissionId);

        return tpermission;
    }


    /**
    * 根据条件permissionId查询Tpermission一个详情信息
    *
    * @param permissionId 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Tpermission一个详情信息", notes = "查询Tpermission一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "permissionId", value = "",dataType = "java.lang.Integer", paramType = "path")
    })
    @GetMapping(value = "/load/permissionId/{permissionId}")
    @ResponseBody
    public Permission loadByPermissionId(@PathVariable java.lang.Integer permissionId) {
        if(permissionId==null){
           return null;
        }
        Permission tpermission = tpermissionSV.loadByPermissionId(permissionId);

        return tpermission;
    }


    /**
    * 查询Tpermission信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Tpermission信息集合", notes = "查询Tpermission信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<Permission> list( @ApiIgnore Permission tpermission, Integer curPage, Integer pageSize) {
        Page<Permission> page=new Page<Permission>(pageSize,curPage);
        List<Permission> tpermissions = tpermissionSV.list(tpermission,page.genRowStart(),page.getPageSize());
        int total = tpermissionSV.count(tpermission);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return tpermissions;
    }


    /**
    * 创建Tpermission
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Tpermission", notes = "创建Tpermission")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query"),
    @ApiImplicitParam(name = "pid", value = "父级菜单id", paramType = "query"),
    @ApiImplicitParam(name = "parentName", value = "父级菜单名称", paramType = "query"),
    @ApiImplicitParam(name = "type", value = "菜单类型 1:目录 2：菜单 2：按钮", paramType = "query"),
    @ApiImplicitParam(name = "url", value = "菜单url", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "授权编码", paramType = "query"),
    @ApiImplicitParam(name = "color", value = "颜色", paramType = "query"),
    @ApiImplicitParam(name = "icon", value = "图标", paramType = "query"),
    @ApiImplicitParam(name = "sort", value = "排序", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public Permission build( @ApiIgnore Permission tpermission) {
        tpermissionSV.save(tpermission);
        return tpermission;
    }


    /**
    * 修改Tpermission
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Tpermission", notes = "修改Tpermission")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "permissionId", value = "", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query"),
        @ApiImplicitParam(name = "pid", value = "父级菜单id", paramType = "query"),
        @ApiImplicitParam(name = "parentName", value = "父级菜单名称", paramType = "query"),
        @ApiImplicitParam(name = "type", value = "菜单类型 1:目录 2：菜单 2：按钮", paramType = "query"),
        @ApiImplicitParam(name = "url", value = "菜单url", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "授权编码", paramType = "query"),
        @ApiImplicitParam(name = "color", value = "颜色", paramType = "query"),
        @ApiImplicitParam(name = "icon", value = "图标", paramType = "query"),
        @ApiImplicitParam(name = "sort", value = "排序", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public Permission modify(@ApiIgnore Permission tpermission) {
        tpermissionSV.modify(tpermission);
        return tpermission;
    }


}
